/**
 * Project Name:hyh-web
 * File Name:UserController.java
 * Package Name:com.hyh.controller
 * Date:2018年9月5日下午3:14:05
 *
*/

package com.hyh.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hyh.model.entity.User;
import com.hyh.repository.UserRepository;
import com.hyh.result.Result;

/**
 * ClassName:UserController
 * Reason:	 TODO ADD REASON.
 * Date:     2018年9月5日 下午3:14:05
 * @author   huangyihao
 * @version  
 * @see 	 
 */
@RestController
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserRepository userRepository;
	
	@PostMapping("save")
	public Result<Long> save(@RequestBody @Valid User user){
		userRepository.add(user);
		return new Result<Long>(user.getId());
	}
	
	@GetMapping("list")
	public List<User> list() {
		List<User> list = userRepository.all();
		return list;
	}
	
}
